package com.hushan.elevator.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {
    //http://localhost:10220/swagger-ui/index.html
    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI()
                .info(this.getApiInfo());
    }

    @Bean("deviceGroupApi")
    public GroupedOpenApi deviceGroupApi() {
        return GroupedOpenApi.builder().group("设备模块组")
                .pathsToMatch("/device/**")
                .build();
    }

    @Bean("deptGroupApi")
    public GroupedOpenApi deptGroupApi() {
        return GroupedOpenApi.builder().group("单位模块组")
                .pathsToMatch("/dept/**")
                .build();
    }

    @Bean("userGroupApi")
    public GroupedOpenApi userGroupApi() {
        return GroupedOpenApi.builder().group("用户模块组")
                .pathsToMatch("/user/**")
                .build();
    }

    @Bean("riskGroupApi")
    public GroupedOpenApi riskGroupApi() {
        return GroupedOpenApi.builder().group("风险模块")
                .pathsToMatch("/risks/**")
                .build();
    }

    @Bean("sysGroupApi")
    public GroupedOpenApi sysGroupApi() {
        return GroupedOpenApi.builder().group("系统模块组")
                .pathsToMatch("/sys/**")
                .build();
    }

    private Info getApiInfo() {
        return new Info()
                .title("湖山智能电梯平台")
                .description("湖山智能电梯平台Swagger3示例文档")
                .summary("采用restful接口风格，使用spring security进行认证及权限校验")
                .version("1.0");
    }
}

